let socket = new Phoenix.Socket("/socket", {params: {token: window.userToken}})
socket.connect()

// Now that you are connected, you can join channels with a topic:
let channel = socket.channel("timer:update", {})
channel.join()
  .receive("ok", resp => { console.log("Joined successfully", resp) })
  .receive("error", resp => { console.log("Unable to join", resp) })

channel.on('new_time', msg => {
  console.log("The timer is: ", msg.time)
  document.getElementById('status').innerHTML = msg.response
  document.getElementById('timer').innerHTML = msg.time
})

let startTimer = function (event) {
  event.preventDefault()
  channel.push('start_timer', {})
    .receive('ok', resp => { console.log('Started timer', resp) })
}
document.getElementById('start-timer').onclick = startTimer


